/**
 * Created by 门梦雷 and yl on 2017/5/26.
 */

$(document).ready(function(){
    apply();
});


function apply(){
    $.ajax({
        type: "post",
        url: '/api/v1/discovery/index',
        success: function (data) {
            //获取数据后初始化页面
        //    alert("初始化成功");
            $('#enter-family').html(data.f_count);
            $('#number-of-people').html(data.fp_count);
            $('#newly-increased').html(data. y_count );
        },
        error: function (msg) {
            console.log(msg)
        }
    });
}



/*
 class="application-approve" 批准
 class="application-refused" 拒绝
 家族成员申请
 */
//如果批准
$(".application-approve").click(function(){
    var oApplay =  $(this)
    var personId=$(this).siblings(".user").val();//申请加入家族的用户id
    var familyId=$(this).siblings(".fid").val();
    var activeId=$(this).siblings(".nid").val();
    var data={
        "id": activeId,
        "userId": personId,
        "familyId" : familyId
    }
    if('y'==$(this).val()){

        $.ajax({
         type: "post",
         url: '/h5/family/updatePersonFid',
         data:data,
         success: function (data) {
             oApplay.val("已批准")
             refresh();
         },
         error: function (msg) {
            console.log(msg)
         }
        })
    }else{
        alert("失败");
    }
});


//如果拒绝
$(".application-refused").click(function(){
    var activeId=$(this).siblings(".nid").val();
// alert("shanchu"+activeId);
    var data={
        "id": activeId,
    }
    if('n'==$(this).val()){
       // alert(data);
        $.ajax({
            type: "post",
            url: '/h5/family/deletePersonFid',
            data:data,
            success: function (data) {
                refresh();
              //  alert("确定删除"+activeId);

            },
            error: function (msg) {
                console.log(msg)
            }
        })
    }else{
        alert("mdzz");
    }
});
function refresh(){
    window.location.reload();
}


